package ejbSessionBeans;

import ejbEntity.Album;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author bbaquero
 */
@Stateless
public class AlbumFacade implements AlbumFacadeLocal {
    @PersistenceContext
    private EntityManager em;

    public void create(Album album) {
        em.persist(album);
    }

    public void edit(Album album) {
        em.merge(album);
    }

    public void remove(Album album) {
        em.remove(em.merge(album));
    }

    public Album find(Object id) {
        return em.find(Album.class, id);
    }

    public List<Album> findAll() {
        return em.createQuery("select object(o) from Album as o").getResultList();
    }

    public List<Album> findByIdArtista(Integer idArtista){
        return em.createNamedQuery("Album.findByIdArtista").setParameter("idArtista", idArtista).getResultList();
    }

}